package com.fyw.magichome.ui;

import android.content.Context;
import android.os.Bundle;
import android.view.View;

import com.ezvizuikit.open.EZUIError;
import com.ezvizuikit.open.EZUIKit;
import com.ezvizuikit.open.EZUIPlayer;
import com.fyw.magichome.BaseActivity;
import com.fyw.magichome.Constants;
import com.fyw.magichome.R;

import java.util.Calendar;

/**
 * Created by FYW on 2017/9/26.
 */

public class CameraPlayActivity extends BaseActivity implements EZUIPlayer.EZUIPlayerCallBack {
    private EZUIPlayer mPlayer;

    private String deviceSerial;
    private int channelNo;

    private String playUrl;

    @Override
    public void initParam(Bundle param) {
        deviceSerial = param.getString("deviceSerial");
        channelNo = param.getInt("channelNo");

        playUrl = "ezopen://open.ys7.com/" + deviceSerial + "/" + channelNo + ".hd.live";
    }

    @Override
    public View bindView() {
        return null;
    }

    @Override
    public int bindLayout() {
        return R.layout.activity_camera_play;
    }

    @Override
    public void initView(View view) {
        //获取EZUIPlayer实例
        mPlayer = (EZUIPlayer) findViewById(R.id.playerUi);
        //设置授权token
        EZUIKit.setAccessToken(Constants.accessTokenStr);
        //设置播放回调callback
        mPlayer.setCallBack(this);
        //设置播放参数
        mPlayer.setUrl(playUrl);
        //开始播放
        mPlayer.startPlay();
    }

    @Override
    public void doBusiness(Context mContext) {

    }

    @Override
    protected void onStop() {
        super.onStop();
        //停止播放
        mPlayer.stopPlay();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //释放资源
        mPlayer.releasePlayer();
    }


    @Override
    public void onPlaySuccess() {

    }

    @Override
    public void onPlayFail(EZUIError ezuiError) {
        showToast(ezuiError.getErrorString());
    }

    @Override
    public void onVideoSizeChange(int i, int i1) {

    }

    @Override
    public void onPrepared() {

    }

    @Override
    public void onPlayTime(Calendar calendar) {

    }

    @Override
    public void onPlayFinish() {

    }
}
